home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume28 / ssh-1.2 / part01 next >
Encoding:
Text File  |  1992-03-15  |  11.4 KB  |  405 lines

  1. Newsgroups: comp.sources.misc
  2. From: etxerus@james.ericsson.se (Hans Beckerus LG/TH)
  3. Subject:  v28i098:  ssh-1.2 - Split & Strip appended shell archives, Part01/01
  4. Message-ID: <1992Mar13.052055.19370@sparky.imd.sterling.com>
  5. X-Md4-Signature: a78bea57610507a5cc30c08acbcfa258
  6. Date: Fri, 13 Mar 1992 05:20:55 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: etxerus@james.ericsson.se (Hans Beckerus LG/TH)
  10. Posting-number: Volume 28, Issue 98
  11. Archive-name: ssh-1.2/part01
  12. Environment: UNIX
  13. Supersedes: ssh: Volume 28, Issue 80
  14.  
  15.                 --------------------------
  16.                      SSH version 1.20
  17.                 --------------------------   
  18.  
  19. This program strips and splits multiple/single part shell
  20. archives and stores the result in 'partXX' files.
  21.  
  22.  In this version of ssh I have: 
  23.  
  24.   - Fixed some minor bugs.
  25.  
  26.   - Added the -x option that makes it possible to
  27.     extract files in multipart archives. 
  28.  
  29.   - Added usage and version information options.
  30.  
  31.   - Increased the functionality so that it will work
  32.     on almost all archives. I have only seen one type
  33.     that does not work and that is when the archives
  34.     contains archives themselves.
  35.  
  36.   - Updated the code so it will compile on all SYS V
  37.     machines too (I hope).
  38.  
  39.  This program has been tested on the SUN/SPARC and 
  40.  the HP9000/700 series.
  41.  
  42.                          /Hans
  43. ----------------------------------
  44. #! /bin/sh
  45. # This is a shell archive.  Remove anything before this line, then unpack
  46. # it by saving it into a file and typing "sh file".  To overwrite existing
  47. # files, type "sh file -c".  You can also feed this as standard input via
  48. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  49. # will see the following message at the end:
  50. #        "End of shell archive."
  51. # Contents:  Makefile README ssh.c
  52. # Wrapped by etxerus@james16 on Thu Mar 12 15:59:26 1992
  53. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  54. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  55.   echo shar: Will not clobber existing file \"'Makefile'\"
  56. else
  57. echo shar: Extracting \"'Makefile'\" \(655 characters\)
  58. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  59. X#
  60. X# Simple makefile for ssh 1.20
  61. X#
  62. X
  63. X# Destination directory for binary
  64. XBINDIR= /usr/local/bin
  65. X
  66. XCC= cc
  67. XFLAGS= -O
  68. XPROG= ssh
  69. XSOURCES= ssh.c
  70. XOBJS= ssh.o
  71. X
  72. X# Do not change the SHELL definition except if
  73. X# (by some reason) 'sh' is located somewhere
  74. X# else then in /bin.
  75. XDSHELL=-DSHELL=\"/bin/sh\"
  76. X
  77. X# SUN/SPARC:
  78. X# This should work for all SUN:s.
  79. XTARGET= -DSUN
  80. X# SYS5:
  81. X# This should work for all System V machines.
  82. X#TARGET= -DSYSV
  83. X
  84. XSCCSID= -DSCCSID
  85. XDEFINES= $(TARGET) $(SCCSID) $(DSHELL)
  86. XCFLAGS= $(FLAGS) $(DEFINES)
  87. X
  88. X$(PROG): $(OBJS)
  89. X    $(CC) $(CFLAGS) -o $(PROG) $(OBJS) 
  90. X
  91. Xclean:
  92. X    rm -f core $(PROG) $(OBJS)
  93. X
  94. Xinstall: $(PROG)
  95. X    strip $(PROG)
  96. X    mv $(PROG) $(BINDIR)
  97. END_OF_FILE
  98. if test 655 -ne `wc -c <'Makefile'`; then
  99.     echo shar: \"'Makefile'\" unpacked with wrong size!
  100. fi
  101. # end of 'Makefile'
  102. fi
  103. if test -f 'README' -a "${1}" != "-c" ; then 
  104.   echo shar: Will not clobber existing file \"'README'\"
  105. else
  106. echo shar: Extracting \"'README'\" \(1493 characters\)
  107. sed "s/^X//" >'README' <<'END_OF_FILE'
  108. X                --------------------------
  109. X                     SSH version 1.20
  110. X                --------------------------   
  111. X
  112. X In this version of ssh I have: 
  113. X
  114. X  - Fixed some minor bugs.
  115. X
  116. X  - Added the -x option that makes it possible to
  117. X    extract files in multipart archives. 
  118. X
  119. X  - Added usage and version information options.
  120. X
  121. X  - Increased the functionality so that it will work
  122. X    on allmost all archives. I have only seen one type
  123. X    that does not work and that is when the archives
  124. X    contains archives themselves.
  125. X
  126. X  - Updated the code so it will compile on all SYS V
  127. X    machines too (I hope).
  128. X
  129. X If you find any faults while using this program please
  130. X notify me. Read the sourcecode for more information.
  131. X
  132. X To compile type 'make install'. For SYS V machines
  133. X see the makefile.
  134. X
  135. X This program has been tested on the SUN/SPARC and 
  136. X the HP9000/700 series.
  137. X
  138. X
  139. X Usage: ssh [-h]
  140. X            [-x] < shar_archive
  141. X            [-v]
  142. X
  143. X Options:
  144. X   -h       - Display usage information. 
  145. X   -x       - Extract files in archive instead
  146. X              of spliting it into parts.
  147. X   -v       - Display version information.
  148. X
  149. X   Without any options ssh splits archives
  150. X   into extractable 'PartXX' files.
  151. X
  152. X
  153. X Cheers!
  154. X________________________________________________________________________________
  155. XHans Beckerus                  Phone : +46 8 719 59 60     
  156. XEricsson Telecom AB            Memo  : ETX.ETXERUS
  157. XAXE System Design              Email : etxerus@james.ericsson.se
  158. X126 25 Stockholm
  159. XSWEDEN
  160. END_OF_FILE
  161. if test 1493 -ne `wc -c <'README'`; then
  162.     echo shar: \"'README'\" unpacked with wrong size!
  163. fi
  164. # end of 'README'
  165. fi
  166. if test -f 'ssh.c' -a "${1}" != "-c" ; then 
  167.   echo shar: Will not clobber existing file \"'ssh.c'\"
  168. else
  169. echo shar: Extracting \"'ssh.c'\" \(6246 characters\)
  170. sed "s/^X//" >'ssh.c' <<'END_OF_FILE'
  171. X/* @(#)ssh.c 1.20 92/03/11 (HaB)
  172. X *
  173. X * NAME:
  174. X *    ssh
  175. X *
  176. X * SYNTAX:
  177. X *    ssh [-h]
  178. X *        [-x] < shar_archive
  179. X *        [-v] 
  180. X *
  181. X * OPTIONS:
  182. X *    -h    Display usage information.
  183. X *
  184. X *    -x    Extract files in archive instead
  185. X *          of spliting it into parts. 
  186. X *
  187. X *    -v    Display version information. 
  188. X *
  189. X *    Without any options ssh splits archives
  190. X *    into extractable 'PartXX' files.
  191. X *
  192. X * DESCRIPTION:
  193. X *    Splits, strips and extracts appended shell
  194. X *    archives and stores the result in 'PartXX'
  195. X *    files (not when extracting). 
  196. X *
  197. X * NOTES:
  198. X *    The program should work on all archives created
  199. X *    using 'shar' (or equals) provided that they have
  200. X *    not been changed since they were first generated.  
  201. X *
  202. X * BUGS:
  203. X *    I have noticed that when the archives contains
  204. X *    archives themselves (happens sometimes) it does 
  205. X *    not work properly.
  206. X *
  207. X * DATE:
  208. X *    1992-03-11
  209. X *
  210. X * AUTHOR:
  211. X *    Hans C. Beckerus
  212. X *    etxerus@james.ericsson.se
  213. X *
  214. X * DISCLAIMER:
  215. X *    This program is free to distribute to anyone aslong 
  216. X *    as the code is not changed in anyway without me
  217. X *    knowing about it.  
  218. X *
  219. X *                                            /HaB :-)
  220. X */
  221. X
  222. X#include <stdio.h>
  223. X#include <string.h>
  224. X#include <malloc.h>
  225. X
  226. X#define SEARCH   0
  227. X#define START    1
  228. X#define INSIDE   2
  229. X#define MSTEP    80     /* Allocation steps       */
  230. X#define SEARCHP  5      /* No. of search patterns */ 
  231. X
  232. X#ifndef SHELL
  233. X#define SHELL  "/bin/sh"     /* Just in case... */
  234. X#endif
  235. X
  236. X#ifdef SYSV     /* HPUX/SYSV */
  237. X#define nl_fprintf  fprintf
  238. X#define nl_sprintf  sprintf
  239. X#define nl_strcmp   strcmp
  240. Xsize_t msize;
  241. X#endif
  242. X
  243. X#ifdef SUN     /* SunOS/Berkeley */
  244. Xunsigned int msize;
  245. X#endif
  246. X
  247. X#ifdef SCCSID
  248. Xchar sccsid[] = "@(#)ssh.c 1.20  92/03/11 (HaB)  etxerus@james.ericsson.se";
  249. X#endif
  250. X
  251. Xenum boolean {     /* Boolean constants */
  252. X    FALSE,
  253. X    TRUE
  254. X};
  255. X
  256. Xchar *pattern[] = {                 /* Add more patterns here if needed.   */ 
  257. X    "# this is a shell archive",    /* NOTE! Remember to increase SEARCHP. */ 
  258. X    "# this is part", 
  259. X    "#!/bin/sh",
  260. X    "# !/bin/sh",
  261. X    "#! /bin/sh"
  262. X};
  263. X
  264. X/* usage:
  265. X * 
  266. X * Display usage information and exit with status rc.
  267. X *
  268. X */
  269. X
  270. Xvoid usage (rc) 
  271. X
  272. Xint rc;     /* Return code */
  273. X
  274. X{
  275. X    puts ("\nUsage: ssh [-h]");
  276. X    puts ("           [-x] < shar_archive");
  277. X    puts ("           [-v]\n");
  278. X    puts ("Options:");
  279. X    puts ("  -h       - This help text.");
  280. X    puts ("  -x       - Extract files in archive instead");
  281. X    puts ("             of spliting it into parts.");
  282. X    puts ("  -v       - Display version information.\n");
  283. X    puts ("  Without any options ssh splits archives");
  284. X    puts ("  into extractable 'PartXX' files.\n");
  285. X    exit (rc);
  286. X}
  287. X
  288. Xvoid main (argn, argv)
  289. X
  290. Xint   argn;
  291. Xchar *argv[];
  292. X
  293. X{
  294. X    FILE     *fr = stdin;          /* Input filepointer  */
  295. X    FILE     *fw;                  /* Output filepointer */
  296. X    FILE     *pipe;                /* Stream pipe        */
  297. X    int       state = SEARCH;      /* The current state  */
  298. X    int       fc = 0;              /* File part counter  */
  299. X    int       extract = FALSE;     /* Extract/write flag */
  300. X    char     *s;                   /* Read line          */
  301. X    char      fout[7];             /* Output filenames   */
  302. X    register  j = 0;               /* Counter            */
  303. X    register  c;                   /* Read character     */
  304. X
  305. X    /* Check the arguments if any */
  306. X    while (--argn) {
  307. X        argv++;
  308. X        if (!(strcmp (*argv, "-h", 2))) {     /* Help screen */
  309. X            if (!(argn-1))     /* Single option */
  310. X                usage (0);
  311. X        }
  312. X        else if (!(strcmp (*argv, "-x"))) {     /* Extract files */ 
  313. X            if (!(argn-1)) {     /* Single option */
  314. X                extract = TRUE;
  315. X                continue;
  316. X            }
  317. X        }
  318. X        else if (!(strcmp (*argv, "-v"))) {
  319. X            if (!(argn-1)) {     /* Single option */
  320. X                puts ("ssh 1.20  (bugs to etxerus@james.ericsson.se)");
  321. X                exit (0);
  322. X            }
  323. X        }
  324. X        usage (1);
  325. X    }  
  326. X
  327. X    msize = MSTEP;
  328. X    s = malloc (msize);     /* Allocate buffer */
  329. X
  330. X    while ((c = getc (fr)) != EOF) {
  331. X    if (c != '\n') {     /* Check for EOL */
  332. X        s[j++] = c;
  333. X            if (j == msize) {
  334. X                msize += MSTEP;
  335. X                if ((s = realloc (s, msize)) == NULL) {
  336. X                    fprintf (stderr, "ssh: Allocation error, cannot continue.\n");
  337. X                    exit (1);
  338. X                }
  339. X            }
  340. X        }
  341. X    else {
  342. X        s[j] = '\0';     /* One line has been read */
  343. X        switch (state) {
  344. X        case SEARCH:
  345. X                    for (j = 0; j < SEARCHP; j++) {
  346. X                        if (!(strncasecmp (s, pattern[j], strlen (pattern[j])))) {
  347. X                            state = START;
  348. X                            break;    
  349. X                        }
  350. X                    }
  351. X                    if (state != START)
  352. X                        break;
  353. X
  354. X        case START:     /* Start writing or extracting */
  355. X                    if (!extract) {
  356. X                sprintf (fout, "Part%.2d", ++fc);
  357. X                fw = fopen (fout, "w");
  358. X                        fprintf (fw, "%s\n", s);
  359. X                    }
  360. X                    else {
  361. X                        if ((pipe = popen (SHELL, "w")) == NULL) {
  362. X                            puts ("ssh: Cannot create process.\n");
  363. X                            exit (1);
  364. X                        }
  365. X                        fprintf (pipe, "%s\n", s);
  366. X                    }
  367. X                    state = INSIDE;
  368. X            break;
  369. X
  370. X                case INSIDE:
  371. X            if (!(strcmp (s, "exit 0"))) {     /* Look for end */
  372. X                        if (!extract) {
  373. X                            fprintf (fw, "%s\n", s);
  374. X                            fclose (fw);
  375. X                        }
  376. X                        else {
  377. X                            fprintf (pipe, "%s\n", s);
  378. X                            pclose (pipe);
  379. X                        }
  380. X                        state = SEARCH;
  381. X                    }
  382. X                    else {
  383. X                        if (extract)
  384. X                            fprintf (pipe, "%s\n", s);
  385. X                        else
  386. X                fprintf (fw, "%s\n", s);
  387. X                    }
  388. X            break;
  389. X            }
  390. X            j = 0;    /* Reset counter */
  391. X        }
  392. X    }
  393. X}
  394. END_OF_FILE
  395. if test 6246 -ne `wc -c <'ssh.c'`; then
  396.     echo shar: \"'ssh.c'\" unpacked with wrong size!
  397. fi
  398. # end of 'ssh.c'
  399. fi
  400. echo shar: End of shell archive.
  401. exit 0
  402.  
  403. exit 0 # Just in case...
  404.